import * as THREE from 'three';

/**
 * 地面
 */
export class Plane extends THREE.Mesh {
  /**
   * 初始化地面
   * @param {Number} width
   * @param {Number} depth
   */
  constructor(options) {
    const defaultOptions = {
      width: 100,
      depth: 100
    };
    const mergeOptions = Object.assign(defaultOptions, options);
    const { width, depth } = mergeOptions;
    const planeGeometry = new THREE.PlaneGeometry(width, depth);
    const planeMaterial = new THREE.MeshBasicMaterial({
      color: 'lightgrey',
      side: THREE.DoubleSide
    });
    const plane = new THREE.Mesh(planeGeometry, planeMaterial);
    plane.position.set(0, 0, 0);
    // 接收阴影
    plane.receiveShadow = true;
    super(planeGeometry, planeMaterial);
    // x旋转90度
    this.rotation.x = Math.PI / 2;
    this.options = mergeOptions;
  }
}
